package com.csgc.camera.widget.dialog.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.csgc.camera.constants.Constants
import com.csgc.camera.util.clickWithTrigger
import com.csgc.camera.widget.dialog.FilterChooseDialog
import com.cysd.spsyxj.databinding.DialogItemFilterBinding

class FilterAdapter(val context: Context):Adapter<FilterAdapter.FilterHolder>() {

    var listener: FilterChooseDialog.OnFilterChooseListener?=null
    private var checkedFilter = 0
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FilterHolder {
        return  FilterHolder(DialogItemFilterBinding.inflate(LayoutInflater.from(context),parent,false))
    }

    override fun onBindViewHolder(holder: FilterHolder, @SuppressLint("RecyclerView") position: Int) {
        val style = Constants.newfilterStyle[position]
        holder.binding.apply {
            tvFilterName.text = style.name
            ivFilterIcon.setImageResource(style.drawable)
            if (checkedFilter == position){
                ivCheckedFilter.visibility = View.VISIBLE
            }else{
                ivCheckedFilter.visibility = View.GONE
            }

//            if (position>3 && !UserPreference.instance.isVip()){
//                ivFilterVipFlag.visibility = View.VISIBLE
//            }else{
//                ivFilterVipFlag.visibility = View.INVISIBLE
//            }

            root.clickWithTrigger {
//                if (position>3 && !UserPreference.instance.isVip()){
//                    VipCenterActivity.launch(context)
//                    return@clickWithTrigger
//                }
                checkedFilter = position
                listener?.onItemCLick(style.style)
                notifyDataSetChanged()
            }

        }
    }

    override fun getItemCount(): Int {
        return Constants.newfilterStyle.size
    }

    inner class FilterHolder(val binding:DialogItemFilterBinding):ViewHolder(binding.root)
}